import QtQuick 2.0

Item {

    readonly property alias isRunning: script.isRunning

    readonly property string gamePath: settings.gamePath

    Script {
        id: script
        workingDirectory: gamePath

        property bool stopRequested: false

        onOutputRead: {
            ui.log(output)
        }

        onFinished: {
            if (stopRequested) {
                stopRequested = false
                // so trying to kill .exe via script
                startClientWrapper("stop")
            }
        }

        function startClientWrapper(command) {
            start(scriptsPath + "client-wrapper", [command])
        }
    }

    function start() {
        script.stopRequested = false
        ui.log("")
        ui.log(qsTr("Starting client..."))
        script.startClientWrapper("start")
    }

    function stop() {
        script.stopRequested = true
        ui.log(qsTr("Terminating client..."))
        script.terminate() // doesn't work as it could.
    }

    function killWineServer() {
        ui.log(qsTr("Killing Wine server..."))
        script.startClientWrapper("killwineserver")
    }
}
